import 'package:flutter/material.dart';
import 'package:ivc/routers/application.dart';
import 'package:ivc/model/bizmodel.dart';

class PartsOrderList extends StatefulWidget {
  final List<PartsOrder> items;
  final bool exchange;
  PartsOrderList({Key key, this.items, this.exchange}) : super(key: key);

  @override
  _PartsOrderListState createState() => _PartsOrderListState();
}

class _PartsOrderListState extends State<PartsOrderList> {
  @override
  void initState() {
    super.initState();
  }

  bool isExchangeOrder(PartsOrder po){
    return po.exchange==this.widget.exchange;
  }

  @override
  Widget build(BuildContext context) {
    List<PartsOrder> filtered = new List<PartsOrder>.from(this.widget.items.where(isExchangeOrder));
    return Center(
        child: ListView.builder(
            itemCount:  filtered.length,
            primary: true,
            padding: const EdgeInsets.all(5.0),
            itemBuilder: (context, position) {
              return Card(
                color: Colors.white38,
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  children: <Widget>[
                    Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment:
                      MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text( filtered[position].sellerName),
                        Text( filtered[position].status,
                            style: TextStyle(color: Colors.redAccent))
                      ],
                    ),
                    Center(
                        child: ListView.builder(
                            shrinkWrap: true,
                            primary: false,
                            itemCount:  filtered[position]
                                .goods
                                .length,
                            padding: const EdgeInsets.all(5.0),
                            itemBuilder: (context, index) {
                              return GestureDetector(
                                child: Row(
                                  mainAxisSize: MainAxisSize.max,
                                  crossAxisAlignment:
                                  CrossAxisAlignment.start,
                                  children: <Widget>[
                                    FadeInImage.assetNetwork(
                                      placeholder:
                                      "assets/images/house.png",
                                      image:
                                      filtered[position]
                                          .goods[index]
                                          .image,
                                      width: 60,
                                      height: 60,
                                    ),
                                    SizedBox(width: 15),
                                    Expanded(
                                      child: Text(
                                          filtered[position]
                                              .goods[index]
                                              .name),
                                    ),
                                    Column(
                                      crossAxisAlignment:
                                      CrossAxisAlignment.end,
                                      children: <Widget>[
                                        Text(
                                            "￥${ filtered[position].goods[index].price.toString()}"),
                                        Text(
                                            "x${ filtered[position].goods[index].quantity.toString()}",
                                            style: TextStyle(
                                                fontSize: 12)),
                                      ],
                                    )
                                  ],
                                ),
                                onTap: () {
                                  Application.router.navigateTo(context, "/parts-item-page/${filtered[position].goods[index].id}/true");
                                },
                              );
                            }))
                  ],
                ),
              );
            }));
  }
}
